package com.ruoyi.activiti.listener;

import com.ruoyi.caigou.api.RemoteBuyBackOrderService;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.SpringUtils;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.system.api.RemoteStockInService;
import com.ruoyi.system.api.domain.caigou.BuyBackOrder;
import com.ruoyi.system.api.domain.store.StockIn;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;

/**
 * @author wangenhao
 * @className BuyBackOrderListener
 * @description 采购退货单监听类
 * @date 2024-11-07 上午11:32
 **/
@Slf4j
public class StockInListener implements ExecutionListener {

    public void notify(DelegateExecution delegateExecution) {
        StockIn stockIn = new StockIn();
        stockIn.setStockInCode(delegateExecution.getProcessInstanceBusinessKey());
        //审核结果
        stockIn.setStatus((Integer) delegateExecution.getVariable("approvalResult"));
//        stockIn.setApprovalOption((String) delegateExecution.getVariable("approvalOption"));

        log.info("StockInListener notify stockIn:{} ", stockIn);
        //TODO 调用采购退货申请修改接口 生成采购退货出库需求单 采购退货应收单
        AjaxResult ajaxResult = SpringUtils.getBean(RemoteStockInService.class).confirmIn(stockIn, SecurityConstants.INNER);
        log.info("ajaxResult:{}", ajaxResult);
    }
}
